package cc.ipost.ipost;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;

public class SettingsActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		this.setContentView(R.layout.settings);
		
		View termsBtn = this.findViewById(R.id.terms_btn);
		View feedbackBtn = this.findViewById(R.id.feedback_btn);
		View logoutBtn = this.findViewById(R.id.logout_btn);
		View homeBtn = this.findViewById(R.id.navhome_btn);
		
		termsBtn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent in = new Intent(SettingsActivity.this, TermsActivity.class);
				SettingsActivity.this.startActivity(in);
			}
		});
		
		feedbackBtn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				feedback();
			}
		});
		
		logoutBtn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				logout();
			}
		});
		
		homeBtn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent in = new Intent(SettingsActivity.this, MainActivity.class);
				SettingsActivity.this.startActivity(in);
			}
		});
	}
	
	private void feedback(){
		//系统邮件系统的动作为android.content.Intent.ACTION_SEND
		Intent email = new Intent(android.content.Intent.ACTION_SEND);
		email.setType("plain/text");
		String emailReciver = "service@ipost.cc";
		String emailSubject = "意見回饋／Feedback";
		String emailBody = "[請告知我們任何您使用上的疑問，我們將盡快為您處理]";

		//设置邮件默认地址
		email.putExtra(android.content.Intent.EXTRA_EMAIL, emailReciver);
		//设置邮件默认标题
		email.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSubject);
		//设置要默认发送的内容
		email.putExtra(android.content.Intent.EXTRA_TEXT, emailBody);
		//调用系统的邮件系统
		startActivity(Intent.createChooser(email, getString(R.string.please_choose_email_app)));
	}
	
	private void logout(){
		MyApplication ma = (MyApplication) getApplication();
		ma.removeUser();
		Intent in = new Intent(SettingsActivity.this, AccountActivity.class);
		SettingsActivity.this.startActivity(in);
	}
	
	

}
